package src.leetcode.everyday.hard_2321;

/**
 * @author liyizzz
 * @description 拼接数组的最大分数
 * @date 2025/1/14 14:10
 */
public class maximumsSplicedArray {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.maximumsSplicedArray(new int[]{60,60,60}, new int[]{10,90,10}));
    }
}

class Solution {
    public int maximumsSplicedArray(int[] nums1, int[] nums2) {
        int n = nums1.length;
        int sum1 = 0, sum2 = 0;
        for (int i = 0; i < n; i++) {
            sum1 += nums1[i];
            sum2 += nums2[i];
        }

        int max = 0, min = 0;
        int sunMax = 0, sunMin = 0;
        for (int i = 0; i < n; i++) {
            sunMax = Math.max(0, sunMax + (nums1[i] - nums2[i]));
            max = Math.max(max, sunMax);
            sunMin = Math.min(0, sunMin + (nums1[i] - nums2[i]));
            min = Math.min(min, sunMin);
        }

        return Math.max(sum1 - min, sum2 + max);
    }
}

